package com.example.baselib.dialog

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.ListPopupWindow.MATCH_PARENT
import androidx.appcompat.widget.ListPopupWindow.WRAP_CONTENT
import androidx.fragment.app.DialogFragment
import com.example.baselib.R

/**
 * Author: sxygsj
 * Date: 2020/4/13 15:23
 * Description: BaseDialog
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
abstract class BaseDialogFragment: DialogFragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        setDialogStyle()
        val view =inflater.inflate(getContentLayout(), container, false)
        initView(view)
        initData()
        return view
    }

    open fun setDialogStyle(){
        //无标题
        dialog?.requestWindowFeature(STYLE_NO_TITLE)
        //点击外部不消失
        dialog?.setCanceledOnTouchOutside(false)
        //设置 样式
        dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        dialog?.window?.decorView?.setPadding(0, 0, 0, 0)
        dialog?.window?.attributes?.width=  MATCH_PARENT
        dialog?.window?.attributes?.height= WRAP_CONTENT
        dialog?.window?.attributes?.gravity= Gravity.CENTER
    }
    /**
     * @Description: [内容布局的ResId]
     * @Param:
     * @Return:
     */
    protected abstract fun getContentLayout(): Int

    protected abstract fun initView(view :View)

    protected abstract fun initData()

}